<?php
class Daftar extends CI_Controller{
	function __construct() {
		parent::__construct();
		$this->load->model('user_model','user');
	}
	
	function index(){
		$this->daftar();
	}
	
	function daftar(){
		
		$this->load->view('daftar/reg_form');
	}
	
	function make_user(){
		$data['nim']=$this->input->post('nim',TRUE);
		$data['nama']=$this->input->post('nama',TRUE);
		$data['email']=$this->input->post('email',TRUE);
		$data['nohp']=$this->input->post('nohp',TRUE);
		$data['password']=$this->input->post('password_1',TRUE);

		$config['upload_path'] = './public/upload/';
		$config['allowed_types'] = 'gif|jpg|png';
		$config['max_size'] = '1000';

		$this->load->library('upload', $config);

		$type = '.'.substr($_FILES['foto']['type'],6);
		$_FILES['foto']['name']='foto_'.$data['nim'].$type;
		
		$this->upload->do_upload('foto');
		$data_foto = $this->upload->data();
		$data['foto']=UPLOAD.$data_foto['file_name'];
		
		$type = '.'.substr($_FILES['transkrip']['type'],6);
		$_FILES['transkrip']['name']='transkrip_'.$data['nim'].$type;
		
		$this->upload->do_upload('transkrip');
		$data_transkrip = $this->upload->data();
		$data['transkrip']=UPLOAD.$data_transkrip['file_name'];
		
		$insert_result = $this->user->new_user($data);
		
		if($insert_result){
			$user_data = array(
				'nim'=>$data['nim'],
				'nama'=>$data['nama'],
				'nilai_tes'=>0,
				'role'=>'asisten'
			);
			$this->session->set_userdata($user_data);
			redirect(HOME);
		}else{
			$display['data'] = 'NIM anda telah ada';
			$this->load->view('template/view_message',$display);
		}
	}	
}
/** End of file */